package com.member1.control;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.member1.domain.Member;
import com.member1.mapper.MemberMapper;
import com.member1.service.MemberService;
import com.member1.util.MemberSearch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("member")
public class MemberControl {
    @Autowired
    public MemberService memberService;
    @Resource
    public MemberMapper memberMapper;
    @GetMapping("list")
    public List<Member> selectAll(){
        return memberService.selectAll();
    }
    @PostMapping("add")
    public boolean addStudent(@RequestBody Member member){
        boolean flag= memberService.save(member);
        return flag;
    }
    @PostMapping("delete/{memberId}")
    public boolean delMember(@PathVariable int memberId){
        int flag= memberMapper.deleteById(memberId);
        return flag==1;
    }
    @PostMapping("update/{memberId}")
    public boolean updateMember(@PathVariable int memberId,@RequestBody Member member){
        member.setMemberId(memberId);
        boolean flag= memberService.updateById(member);
        return flag;
    }
    @GetMapping("modify")
    public Object queryStudentPage(@RequestBody MemberSearch studentSearch){
        Page<Member>page=new Page<>(studentSearch.getPageNo(),studentSearch.getPageSize());
        QueryWrapper<Member>wrapper=new QueryWrapper<>();
        Object obj;
        obj= memberMapper.selectPage(page,wrapper);
        System.out.println("总条数:"+page.getTotal());
        return obj;
    }
}
